import React from 'react';

export default class WechatLinkList extends React.Component {
  constructor(props) {
    super(props)
  }

  renderList() {
    var self = this;
    var content = [];
    if (this.props.data && this.props.data.length > 0) {
      this.props.data.forEach(function(data, index) {
        var status = ""
        if (data.is_open) {
          status = "已开启 "
        }else {
          status = "已关闭 "
        }

        if (data.need_bind) {
          status += "需要绑定"
        }else {
          status += "不需要绑定"
        }

        content.push((
          <tr>
            <td>{data.name}</td>
            <td>{data.link}</td>
            <td>{status}</td>
            <td>
              <a className="edit" onClick={(event)=>self.props.onDetailClick(data)}>编辑</a>
            </td>
          </tr>
        ))
      })
    }

    return content
  }

  render() {
    return(
      <div className="unit-setting-list setting-list">
        <table className="table">
          <thead>
            <tr className="table-title">
              <th className="no">名称</th>
              <th className="name">链接</th>
              <th className="admin">状态</th>
              <th className="edit">操作</th>
            </tr>
          </thead>
          <tbody>
            {this.renderList()}
          </tbody>
        </table>
      </div>
    )
  }
}
